<?php


class nnci_l_product
{
    public function __construct() {
    }

    public function new_obj()
    {
        $obj = new nnci_m_product();
        return $obj;
    }
    
    public function return_table()
    {
        $obj = new nnci_m_product();
        $obj->query('SELECT * FROM product_nnci');
        return $obj;
    }

    /**
     * Counts users found under the search
     *
     * @param   string      nnc_id
     * @return  int         number of user found
     */
    public static function nncid_exists($nnc_id, $id_edited=-1)
    {
        $obj = new nnci_m_product();

        if($id_edited==-1)
        {
            $obj->get_by_nnc_id($nnc_id);
            return $obj->exists();
        }
        else
        {
            $obj->get_by_nnc_id($nnc_id);
            if($obj->exists())
            {
                $obj->get_by_nnc_id($nnc_id);
                
                if($obj->id==$id_edited)
                    return TRUE;
                else
                    return FALSE;
            }
            else
                return TRUE;
        }
    }

    public static function get_by_id($id)
    {
        $obj = new nnci_m_product();
        return $obj->get_by_id($id);
    }

    public static function create_nncid($nnc_id, $desc="EMPTY") {
        $obj = new nnci_m_product();
        $obj->nnc_id = $nnc_id;
        $obj->desc = $desc;
        $obj->save();
        return $obj;
    }
    
    public static function save_nncid($id, $nnc_id, $desc="EMPTY") {
        $obj = nnci_l_product::get_by_id($id);
        $obj->nnc_id = $nnc_id;
        $obj->desc = $desc;
        $obj->save();
        return $obj;
    }

}
?>
